﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;
using System.Windows.Forms;

namespace MedicalSystem.SamrtReport.Toolbox.Configuration
{
   public static  class ToolboxControlSettings
    {
      
       static  void RegisterControlType( ToolboxControlCollection controlColletion,Dictionary<string, Type> controlType)
       {
          
           foreach (ToolboxControlElement element in controlColletion)
           {
              
               Type T = Type.GetType(element.Type);

               if (T == null)
               {
                   System.Diagnostics.Trace.WriteLine(string.Format("无法加载类型为<{0}>的工具箱控件", element.Type));
               }
                  

               controlType.Add(element.Name, T);
           }

          
       }
       public static ToolboxControlSection GetConfigurationSection()
       {
           return (ToolboxControlSection)ConfigurationManager.GetSection("toolboxControlSettings");
       }

       public static Dictionary<string, Type> GetMobileCustomControlType()
       {
           Dictionary<string, Type> mobileControlType = new Dictionary<string, Type>();

           RegisterControlType(GetConfigurationSection().MobileFormToolboxControls, mobileControlType);

           return mobileControlType;
       }

       public static Dictionary<string, Type> GetBasicControlType()
       {
           Dictionary<string, Type> basicControlType = new Dictionary<string, Type>();

           RegisterControlType(GetConfigurationSection().BasicToolboxControls, basicControlType);

           return basicControlType;
       }
       public static Dictionary<string ,Type> GetWindowsCustomControlType()
       {
           Dictionary<string, Type> windowsControlType = new Dictionary<string, Type>();

           RegisterControlType(GetConfigurationSection().WindowsFormToolboxControls, windowsControlType);

           return windowsControlType;
       }
    }
}
